package tree.simple;

import java.util.Deque;
import java.util.LinkedList;
import java.util.List;

public class MaximumDepthOfNaryTree_559 {

    public int maxDepth(Node root) {
        int res = 0;
        if (root == null) {
            return res;
        }
        Deque<Node> queue = new LinkedList<>();
        queue.offer(root);
        while (!queue.isEmpty()) {
            int size = queue.size();
            while(size-- > 0) {
                Node n = queue.poll();
                for (Node child : n.children) {
                    queue.offer(child);
                }
            }
            res++;
        }
        return res;
    }

    public int dfs(Node node) {
        if (node == null) {
            return 0;
        }

        int count = 0;
        for (Node child : node.children) {
            count = Math.max(count, dfs(child));
        }
        return count + 1;
    }
    class Node {
        public int val;
        public List<Node> children;

        public Node() {
        }

        public Node(int _val) {
            val = _val;
        }

        public Node(int _val, List<Node> _children) {
            val = _val;
            children = _children;
        }
    }

}
